873
class Solution {
    public int lenLongestFibSubseq(int[] arr) {
        int len = arr.length;
        int[][] dp = new int[len][len];
        int max = 2;
        MapInteger, Integer map = new TreeMap();
        for (int i = 0; i  len; i++) {
            map.put(arr[i], i);
        }
        for (int i = 0; i  len; i++) {
            for (int j = i+1; j  len; j++) {
                if (map.containsKey(arr[j]-arr[i])) {
                    if (arr[j]-arr[i]  arr[i]) {
                        dp[i][j] = dp[map.get(arr[j]-arr[i])][i] + 1;
                    } else {
                        dp[i][j] = 2;
                    }
                } else {
                    dp[i][j] = 2;
                }
                max = Math.max(dp[i][j], max);
            }
        }
        return max  3  0  max;
    }
}